<template>
  <div>
    <tableComponents
      :pagination="{ currentPage, pageSize, total: list.all_num }"
      :isHavePagination="true"
      :isHaveExport="false"
      :isHaveAdd="false"
      :searchData="userSearchData"
      @sendUserSearch="getSearch"
      @handleCurrentChange="handleCurrentChange"
      @handleSizeChange="handleSizeChange"
    >
      <template v-slot:table>
        <el-table
          ref="multipleTable"
          :data="list.data"
          stripe
          v-loading="loading"
          header-row-class-name="head_color"
          tooltip-effect="dark"
          style="width: 99.8%"
          @selection-change="handleSelectionChange"
        >
          <el-table-column label="城市" min-width="120">
            <template slot-scope="scope">{{ scope.row.city_name }}</template>
          </el-table-column>

          <el-table-column label="国家" min-width="120">
            <template slot-scope="scope">{{ scope.row.country }}</template>
          </el-table-column>

          <el-table-column label="机场" min-width="120">
            <template slot-scope="scope">{{ scope.row.plane_name }}</template>
          </el-table-column>

          <el-table-column label="代码" min-width="120">
            <template slot-scope="scope">{{ scope.row.plane_code }}</template>
          </el-table-column>

          <el-table-column prop="name" label="是否热门" min-width="125">
            <template slot-scope="scope">
              <el-switch
                class="zdySwith"
                :width="82"
                v-model="scope.row.is_plane_hot"
                active-color="#1aad19"
                inactive-color="#ffffff"
                active-text="已开启"
                inactive-text="已关闭"
                active-value="1"
                @change="getIs($event, scope.row)"
                inactive-value="0"
              ></el-switch>
            </template>
          </el-table-column>

          <el-table-column prop="name" label="是否显示" min-width="125">
            <template slot-scope="scope">
              <el-switch
                class="zdySwith"
                :width="82"
                v-model="scope.row.is_show"
                active-color="#1aad19"
                inactive-color="#ffffff"
                active-text="已开启"
                inactive-text="已关闭"
                active-value="1"
                @change="getIs($event, scope.row)"
                inactive-value="0"
              ></el-switch>
            </template>
          </el-table-column>
          <!-- <el-table-column label="操作" min-width="120">
            <template slot-scope="scope">
              <el-row class="myblank">
                <el-button
                  :loading="$store.state.isLoading"
                  size="mini"
                  @click="editbtn(scope.row)"
                  type="primary"
                  >编辑</el-button
                >
              </el-row>
            </template>
          </el-table-column> -->
        </el-table>
      </template>
    </tableComponents>

    <el-dialog
      :close-on-click-modal="false"
      title="编辑"
      class="tl size_13"
      width="800px"
      :visible.sync="dialogFormVisible"
    >
      <el-form :model="live_single" ref="form" label-width="250px">
        <el-form-item label="矿机名称：">
          <el-col :span="12">
            <el-input
              type="text"
              :rows="6"
              clearable
              placeholder="请输入矿机名称"
              v-model="live_single.title"
              autocomplete="off"
            ></el-input>
          </el-col>
        </el-form-item>
        <el-form-item label="USDT数量：">
          <el-col :span="12">
            <el-input
              type="text"
              :rows="6"
              clearable
              placeholder="请输入USDT数量"
              v-model="live_single.money"
              autocomplete="off"
            >
            </el-input>
          </el-col>
        </el-form-item>
        <el-form-item label="平台币数量：">
          <el-col :span="12">
            <el-input
              type="text"
              :rows="6"
              clearable
              placeholder="请输入平台币数量"
              v-model="live_single.money1"
              autocomplete="off"
            >
            </el-input>
          </el-col>
        </el-form-item>
        <el-form-item label="算力-千分比：">
          <el-col :span="12">
            <el-input
              type="text"
              :rows="6"
              clearable
              placeholder="请输入算力-千分比"
              v-model="live_single.slqfb"
              autocomplete="off"
            >
              <template slot="append">‰</template>
            </el-input>
          </el-col>
        </el-form-item>
        <el-form-item label="限购数量：">
          <el-col :span="12">
            <el-input
              type="text"
              :rows="6"
              clearable
              placeholder="请输入限购数量,0为不限制"
              v-model="live_single.xgsl"
              autocomplete="off"
            >
              <template slot="append">‰</template>
            </el-input>
          </el-col>
        </el-form-item>
        <el-form-item label="直推实名人数：">
          <el-col :span="12">
            <el-input
              type="text"
              :rows="6"
              clearable
              placeholder="请输入直推实名人数"
              v-model="live_single.ztsmrs"
              autocomplete="off"
            >
            </el-input>
          </el-col>
        </el-form-item>
        <el-form-item label="矿机费用：">
          <el-col :span="12">
            <el-input
              type="text"
              :rows="6"
              clearable
              placeholder="请输入矿机费用"
              v-model="live_single.wku"
              autocomplete="off"
            >
            </el-input>
          </el-col>
        </el-form-item>
        <el-form-item label="总限购数量：">
          <el-col :span="12">
            <el-input
              type="text"
              :rows="6"
              clearable
              placeholder="请输入总限购数量"
              v-model="live_single.zxgsl"
              autocomplete="off"
            >
            </el-input>
          </el-col>
        </el-form-item>
        <el-form-item label="进度千分比：">
          <el-col :span="12">
            <el-input
              type="text"
              :rows="6"
              clearable
              placeholder="请输入进度"
              v-model="live_single.jdqfb"
              autocomplete="off"
            >
              <template slot="append">‰</template>
            </el-input>
          </el-col>
        </el-form-item>
        <el-form-item class="tc">
          <el-button
            :loading="$store.state.isLoading"
            type="primary"
            @click="editlive(live_single)"
            >编 辑</el-button
          >
        </el-form-item>
      </el-form>
    </el-dialog>
  </div>
</template>
<script>
import { citySearchData } from "@/assets/js/searchData/searchData"; //引入搜索的数据
export default {
  data() {
    return {
      current: "",
      shows: false,
      is_edit: false,
      dialogFormVisible: false,
      live_single: {},
      loading: false,
      list: [],
      allPage: 0,
      allNum: 0,
      pageSize: 10,
      currentPage: 1,
      searchAll: {},
      row: {},
      multipleSelection: [],
      showCity: true,
      userSearchData: citySearchData,
    };
  },
  components: {},
  methods: {
    getShow(val) {
      this.shows = val;
    },
    getSend(row) {
      this.live_single.username = row.username;
      this.live_single.uid = row.id;
    },
    xzshop() {
      this.shows = true;
    },
    sorta(a, b) {
      return b - a;
    },
    sortNew(index, row) {
      var params = {};
      params = row;
      params.id = row.id;
      params.sort = row.sort;
      this.$api.getPage.edit_milltype(params).then((res) => {
        if (res.data.code == 200 && res.data.result) {
          return;
        } else {
          this.$fnc.alertError(res.data.code_desc, res.data.result); //失败弹出框
        }
      });
    },
    handleSelectionChange(val) {
      this.multipleSelection = val;
    },
    deleteAll() {
      //批量删除
      var str = "";
      if (this.multipleSelection.length <= 0) {
        this.$message.error("未选择批量删除");
      } else {
        for (var i in this.multipleSelection) {
          str += this.multipleSelection[i].id + "@";
        }
        str = str.slice(0, -1);
        this.$swal({
          title: "您确定要删除这些信息吗",
          text: "删除后将无法恢复，请谨慎操作！",
          type: "warning",
          showCancelButton: true,
          confirmButtonColor: "#DD6B55",
          confirmButtonText: "是的，我要删除",
          cancelButtonText: "容我三思",
        }).then((willDelete) => {
          if (willDelete.value) {
            this.$api.getPage.del_milltype({ id_str: str }).then((res) => {
              if (res.data.code == 200) {
                this.$swal("删除成功！", res.data.result, "success");
                this.getNewsAll(this.searchAll);
              } else {
                this.$swal("删除失败！", res.data.result, "success");
                this.getNewsAll(this.searchAll);
              }
            });
          }
        });
      }
    },
    deletebtn(id) {
      //删除
      this.$swal({
        title: "您确定要删除这些信息吗",
        text: "删除后将无法恢复，请谨慎操作！",
        type: "warning",
        showCancelButton: true,
        confirmButtonColor: "#DD6B55",
        confirmButtonText: "是的，我要删除",
        cancelButtonText: "容我三思",
      }).then((willDelete) => {
        if (willDelete.value) {
          this.$api.getPage.del_milltype({ id_str: id }).then((res) => {
            if (res.data.code == 200) {
              this.$swal("删除成功！", res.data.result, "success");
              this.getNewsAll(this.searchAll);
            } else {
              this.$swal("删除失败！", res.data.result, "success");
              this.getNewsAll(this.searchAll);
            }
          });
        }
      });
    },
    add_data() {
      this.live_single = {};
      this.is_edit = false;
      this.dialogFormVisible = true;
    },
    onSuccess(pic) {
      this.live_single.piclink = pic;
    },
    getIs(val, row) {
      this.is_edit = true;
      var params = {};
      params = row;
      params.id = row.id;
      console.log(params);
      this.editlive(params);
    },
    getSearch(obj) {
      this.searchAll = obj;
      this.getNewsAll(obj);
    },
    editlive(item) {
      var params = {};

      if (this.is_edit == false) {
        params = item;
        params.show = 1;
        this.$api.getPage.add_milltype(params).then((res) => {
          if (res.data.code == 200) {
            this.dialogFormVisible = false;
            this.$fnc.alertSuccess(res.data.result);
            this.getNewsAll(this.searchAll);
          } else {
            this.$fnc.alertError(res.data.result);
          }
        });
      } else {
        params = item;
        this.$api.getPage.edit_planelists(params).then((res) => {
          if (res.data.code == 200) {
            this.dialogFormVisible = false;
            this.$fnc.alertSuccess(res.data.result);
            this.getNewsAll(this.searchAll);
          } else {
            this.$fnc.alertError(res.data.result);
          }
        });
      }
    },
    editbtn(item) {
      this.is_edit = true;
      this.live_single = JSON.parse(JSON.stringify(item));
      this.dialogFormVisible = true;
    },

    receive_search(obj) {
      this.searchAll = obj;
      this.getNewsAll(obj);
    },
    getNewsAll(data) {
      this.loading = true;
      var params = {};
      data = data || {};
      params = data;
      this.$api.getPage.getplanelists(params).then((res) => {
        if (res.data.code == 200) {
          this.list = res.data.result;
        }
        this.loading = false;
      });
    },
    handleSizeChange(val) {
      var params = this.searchAll;
      params.page = "";
      params.page_size = val;
      this.getNewsAll(params);
      this.pageSize = val;
    },
    handleCurrentChange(val) {
      this.currentPage = parseInt(val);
      var params = this.searchAll;
      params.page = val;
      params.page_size = this.pageSize;
      this.getNewsAll(params);
    },

    reload() {
      this.getNewsAll(this.searchAll);
    },
  },
  beforeCreate() {},
  created() {
    this.getNewsAll();
  },
  computed: {},
};
</script>

<style lang="less" scoped>
.myblank button {
  margin: 5px 5px 0 0;
}
</style>
